#!/usr/bin/env python
# coding=utf8

import requests
import json
import sys
from math import fabs

import datetime, threading, time
from pprint import pprint


headers = {'content-type': 'application/json',
   'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}

config_data = open('config.json')
config = json.load(config_data)
config_data.close()

discount = 0.995

## -----------------------------------------------------------------------
## function about bts rpc
## -----------------------------------------------------------------------
auth = (config["bts_rpc"]["username"], config["bts_rpc"]["password"])
url = config["bts_rpc"]["url"]
change_min = config["price_limit"]["change_min"]
change_max = config["price_limit"]["change_max"]
max_update_hours = config["price_limit"]["max_update_hours"]
sample_timer = config["price_limit"]["sample_timer"]
median_length = config["price_limit"]["median_length"]

asset_list_all = ["PTS", "PPC", "LTC", "BTC", "WTI", "SLV", "GLD", "TRY", "SGD", "HKD", "RUB", "SEK", "NZD", "CNY", "MXN", "CAD", "CHF", "AUD", "GBP", "JPY", "EUR", "USD"]

asset_list_publish = sys.argv
asset_list_publish.pop(0)
asset_list_display = list(set(config["asset_list_display"] + asset_list_publish))

headers = {'content-type': 'application/json'}
request = {
            "method": "blockchain_get_feeds_for_asset",
            "params": ['CNY'],
            "jsonrpc": "2.0",
            "id": 1
          }
responce = requests.post(url, data=json.dumps(request), headers=headers, auth=auth)
feed_list = json.loads(vars(responce)["_content"])["result"]

#print ("res:"+responce)
#print ("feed:"+feed_list)
